package ;

import easelhx.display.Bitmap;
import easelhx.filters.BoxBlurFilter;
import easelhx.js.Image;
import easelhx.utils.Ticker;

/**
 * ...
 * @author 
 */

class FiltersSimpleExample extends Example
{
	private var angle:Float;
	private var range:Float;
	private var speed:Float;
	private var img:Image;
	private var bmp:Bitmap;

	public function new() 
	{
		super();
	}
	
	override public function run():Void 
	{
		super.run();
		
		angle = 0;
		range = 30;
		speed = 0.1;
		img = new Image();
		img.onload = handleImageLoad;
		img.src = "assets/flowers.jpg";
	}
	
	private function handleImageLoad() : Void
	{
		bmp = new Bitmap(img);
		bmp.cache(0, 0, img.width, img.height);

		stage.addChild(bmp);

		Ticker.setFPS(15);
		Ticker.addListener(this);
	}

	private function tick() : Void
	{
		angle += speed;
		updateImage();
	}

	private function updateImage() : Void
	{
		var value = Math.sin(angle)*range;
		bmp.updateCache();
		bmp.filters = [new BoxBlurFilter(value,  value, 2)];
		stage.update();
	}
	
}